package com.zombie.effect;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
import com.zombie.Constants;
import com.zombie.ResourceManager;
import com.zombie.logic.core.ZombieWorld;
import com.zombie.util.Utils;

public class BloodEffect extends AbstractEffect
{

	public float upSpeed = 64f;	
	public float velocity = 0.5f;
	Color color;
	
	public BloodEffect(){
		renderGroup = Constants.GROUP_POST_EFFECT;
		color = Color.RED.cpy();
		color.a = 0.4f;
	}
	
	@Override
	public void update(int delta) {
		setLifeTime(getLifeTime()-delta);
		float x1 = velocity*MathUtils.cos(MathUtils.degRad*angle);
		float y1 = velocity*MathUtils.sin(MathUtils.degRad*angle);
		position.x+= x1;
		position.y+= upSpeed/1000f*delta+y1;
		upSpeed-= 0.2f*delta;
	}

	@Override
	public void draw(SpriteBatch batch, ShapeRenderer shape) {
		Utils.beginShapeRenderer(shape,ShapeType.FilledCircle);

		Gdx.gl.glEnable(GL10.GL_BLEND);
	    Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		shape.setColor(color);
		shape.filledCircle(position.x, position.y, Utils.randomInt(1, 3));
		shape.end();
		Gdx.gl.glDisable(GL10.GL_BLEND);

	}

	@Override
	public void remove() {
		ScalingImageEffect eff = new ScalingImageEffect();
		eff.image = ResourceManager.getImage("meat_"+Utils.rnd.nextInt(3));
		eff.setBounds(position.x-eff.image.getRegionWidth()/2, position.y-eff.image.getRegionHeight()/2, eff.image.getRegionWidth(), eff.image.getRegionHeight());
		eff.scale = 0.3f;
		eff.maxScale = 1.5f;
		eff.scaleVelocity = -0.025f;
		eff.setFullLifeTime(30000);
		ZombieWorld.addEffect(eff);
		color = null;
	}

}
